#!/usr/bin/env bash

set -euo pipefail

# get current path
BASEDIR=$(dirname "$0")


install_with_github() {
    git submodule init && git submodule update
}

install_with_gitee() {
    cp $BASEDIR/.gitmodules $BASEDIR/.gitmodules.github
    cp $BASEDIR/.gitmodules.gitee $BASEDIR/.gitmodules
    git submodule init && git submodule update
    mv $BASEDIR/.gitmodules.github $BASEDIR/.gitmodules
}

main() {

    select remote in github gitee; do
        case $remote in
        github) install_with_github ; break ;;
        gitee) install_with_gitee ; break ;;
        *)
            echo "exit!"
            continue
            ;;
        esac
    done

    stow -d $BASEDIR -t $HOME main

}

main
